package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    @Override
    public void addBed(BedVo bedVo) {
        Bed bed = BeanUtil.toBean(bedVo, Bed.class);
        bed.setCreateBy(1L);
        bed.setBedStatus(0);
        bed.setCreateTime(LocalDateTime.now());
        bed.setUpdateTime(LocalDateTime.now());
        bedMapper.addBed(bed);
    }

    @Override
    public Bed getBedById(Long id) {
        Bed bed = bedMapper.getBedById(id);
        return bed;
    }

    @Override
    public void updateBedById(BedVo bedVo) {
        Bed bed = BeanUtil.toBean(bedVo, Bed.class);
        bed.setUpdateBy(1L);
        bed.setUpdateTime(LocalDateTime.now());
        bedMapper.updateBedById(bed);

    }

    @Override
    public void deleteBedById(Long id) {
        bedMapper.deleteBedById(id);
    }


}

